/**
 * Copyright (c) 2013 Axa Holding Belgium, SA. All rights reserved.
 * This software is the confidential and proprietary information of the AXA Group.
 */
package chabernac.gravidroid.model;

import junit.framework.TestCase;

public class RectTest extends TestCase {
    public void testRectConstructor() {
        Rectangle theRect = Rectangle.constructFrom2Points( new Vector( -5, -5 ), new Vector( 4, 4 ) );

        assertEquals( new Vector( -5, -5 ), theRect.getTopLeft() );
        assertEquals( new Vector( 4, 4 ), theRect.getBottomRight() );
    }

    public void testRectConstructor2() {
        Rectangle theRect = Rectangle.constructFrom2Points( new Vector( 1, 4 ), new Vector( 4, 1 ) );

        assertEquals( new Vector( 1, 1 ), theRect.getTopLeft() );
        assertEquals( new Vector( 4, 4 ), theRect.getBottomRight() );
    }

    public void testRectContains() {
        Rectangle theRect = Rectangle.constructFrom2Points( new Vector( -5, -5 ), new Vector( 4, 4 ) );
        assertTrue( theRect.contains( new Vector( 3, 3 ) ) );
        assertTrue( theRect.contains( new Vector( 0, 0 ) ) );
        assertTrue( theRect.contains( new Vector( -5, 3 ) ) );

        assertTrue( theRect.contains( new Vector( -5, 4 ) ) );
        assertTrue( theRect.contains( new Vector( 4, -4 ) ) );
        assertTrue( theRect.contains( new Vector( -5, -5 ) ) );
        assertTrue( theRect.contains( new Vector( 4, 4 ) ) );

    }

    public void testIntersects() {
        Rectangle theRect1 = Rectangle.constructFrom2Points( new Vector( -2, 2 ), new Vector( -1, 1 ) );
        Rectangle theRect2 = Rectangle.constructFrom2Points( new Vector( 1, 2 ), new Vector( 2, 1 ) );

        assertFalse( theRect1.intersectsWith( theRect2 ) );
        assertFalse( theRect2.intersectsWith( theRect1 ) );
    }

    public void testIntersects2() {
        Rectangle theRect2 = Rectangle.constructFrom2Points( new Vector( 1, 2 ), new Vector( 2, 1 ) );
        Rectangle theRect1 = Rectangle.constructFrom2Points( new Vector( 1, -1 ), new Vector( 2, -2 ) );

        assertFalse( theRect1.intersectsWith( theRect2 ) );
        assertFalse( theRect2.intersectsWith( theRect1 ) );
    }

    public void testIntersects3() {
        Rectangle theRect2 = Rectangle.constructFrom2Points( new Vector( 1, 3 ), new Vector( 3, 1 ) );
        Rectangle theRect1 = Rectangle.constructFrom2Points( new Vector( 2, 2 ), new Vector( 4, 0 ) );

        assertTrue( theRect1.intersectsWith( theRect2 ) );
        assertTrue( theRect2.intersectsWith( theRect1 ) );
    }

    public void testIntersects4() {
        Rectangle theRect2 = Rectangle
                                      .constructFrom2Points( new Vector( 440.573f, 408.00577f ), new Vector( 755.3598f, 752.7169f ) );
        Rectangle theRect1 = Rectangle
                                      .constructFrom2Points( new Vector( 520.16345f, 129.6393f ), new Vector( 835.291f, 467.28494f ) );

        assertTrue( theRect1.intersectsWith( theRect2 ) );
        assertTrue( theRect2.intersectsWith( theRect1 ) );
    }

    public void testIntersects5() {
        Rectangle theRect2 = Rectangle.constructFrom2Points( new Vector( 478.07016f, 471.81744f ),
                                                             new Vector( 801.31024f, 813.9102f ) );
        Rectangle theRect1 = Rectangle.constructFrom2Points( new Vector( 572.47833f, 175.88394f ),
                                                             new Vector( 870.19525f, 500.74118f ) );

        assertTrue( theRect1.intersectsWith( theRect2 ) );
        assertTrue( theRect2.intersectsWith( theRect1 ) );
    }

    public void testIntersects6() {
        Rectangle theRect1 = Rectangle.constructFrom2Points( new Vector( 400.0308f, 326.86487f ),
                                                             new Vector( 700.00323f, 673.20886f ) );
        Rectangle theRect2 = Rectangle.constructFrom2Points( new Vector( 900.00116f, 326.86487f ),
                                                             new Vector( 1200.0004f, 673.20886f ) );

        assertFalse( theRect1.intersectsWith( theRect2 ) );
        assertFalse( theRect2.intersectsWith( theRect1 ) );
    }

    public void testIntersects7() {
        Rectangle theRect2 = Rectangle.constructFrom2Points( new Vector( 337.02652f, 440.70343f ),
                                                             new Vector( 3454.2856f, 3887.12f ) );
        Rectangle theRect1 = Rectangle.constructFrom2Points( new Vector( 680.4983f, 581.45404f ),
                                                             new Vector( 4039.8164f, 3915.1558f ) );

        assertTrue( theRect1.intersectsWith( theRect2 ) );
        assertTrue( theRect2.intersectsWith( theRect1 ) );
    }
}
